<?php
$pageSize = 10;
if (isset($inPageSize)) {
    $pageSize = $inPageSize;
}
// 传入页码
@$inPage = (int)$_POST["page"];
if (isset($inPage) && is_int($inPage) && $inPage > 0) {
    $page = $inPage; //页码
} else {
    $page = 1;
}
// 传入统计用表
$total = $mysqli->query("select count(0) from $tableName"); //取得记录总数$total
$totalPage = ceil($total->fetch_row()[0] / $pageSize); //总页数
$offset = ($page - 1) * $pageSize; //偏移量
// 传入查询内容语句
$sql = $sql . " limit $offset,$pageSize";
$mysqli_result = $mysqli->query($sql);
if ($mysqli_result && $mysqli_result->num_rows > 0) {
    while ($row = $mysqli_result->fetch_assoc()) {
        $rows[] = $row;
    }
}
$total->close();
$mysqli_result->close();
$mysqli->close();